home *** CD-ROM | disk | FTP | other *** search
- Path: beach.and.nl!usenet
- From: jos@and.nl (Jos A. Horsmeier)
- Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
- Subject: Re: Hungarian notation
- Date: 11 Jan 1996 10:26:08 GMT
- Organization: AND Operations Research B.V.
- Message-ID: <4d2ok0$69s@beach.and.nl>
- References: <30C40F77.53B5@swsbbs.com> <marnoldDJEvtJ.1Lx@netcom.com> <4aleun$jlk@ns.RezoNet.NET> <marnoldDJMDBG.CFz@netcom.com> <4asnkr$7b0@solutions.solon.com> <4ath75$e7i@barnacle.iol.ie> <4b4kij$svt@news.microsoft.com> <dewar.819489496@schonberg> <4bd <4cf8hf$8fe@hopi.gate.net> <4cgq30$c0v@weck.brokersys.com> <4cvu68$2jb@macaw.cyberport.com> <4d21og$iab@news.xmission.com>
- NNTP-Posting-Host: klepzeiker.and.nl
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <4d21og$iab@news.xmission.com>, tknarr@xmission.com wrote:
- |In <4cvu68$2jb@macaw.cyberport.com>, tangent@cyberport.com (Warren Young)
- |writes:
-
- |>This is one of the reasons HN is useful. By forcing the programmer to
- |>visit every place that the variable is used, the programmer has an
- |>opportunity to check the semantics of the variable's use. If the type
- |>of the variable has changed, chances are that the semantics have
- |>changed as well. How many times have you changed a variable's type to
- |fix something, only to break something else?
-
- |I find this is false in practice. In general, when I change the declared
- |type of a variable, I'm doing the equivalent of changing an int to a long.
- |The result of that in the presence of HN is a massive amount of monkey-work
- |to visit and change every occurrence of the variable when the only reason
- |for the change is to replace iCount with lCount and nothing more. Since I
- |hate doing manual typographic changes like that and it can be difficult or
- |impossible to write a script to do it automatically in all files involved,
- |I find most often that it does not get done ( and I can't really blame
- |the people who didn't do it ).
-
- |Changes in semantics do happen, but usually as a side-effect of a major
- |change in the fundamental way the code itself works, not as a side-effect
- |of a simple type change. As such they require code changes completely
- |above and beyond the variable names.
-
- IMHO all HN tries to add to the language, is a (weak) notion of domains
- of objects. I thought (but correct me if I'm wrong) that HN adds a name
- prefix to an object name for the 'deeper notion' (read: the semantics or
- domain); it does not prefix every object name with a short prefix
- indicating the type used to implement the domain of an object.
-
- Prefixing 'psz' to every zero terminated string is plain silly if we're
- talking about, say, employee names or beer brand names; something like
- 'empnm' and 'beernm' should have been used instead. Only then, statements
- like:
-
- if (!strcmp(empnmBoss, beernmMyFavBeer))
-
- trigger the reader that something fishy is going on here ... HN, as it
- is used now, doesn't add any clarity to the code at all, i.e. the statement:
-
- if (!strcmp(pszBoss, pszMyFavBeer))
-
- just tells me that I want to compare my favorite beer and a boss's name,
- which is silly too, but it's not the 'psz' prefix that rings a bell here;
- it's just the 'Boss' and 'MyFavBeer' name parts that catch the eye.
-
- Just adding domain name prefixes to the names of objects doesn't help
- anyone; notion of domains should be present in the language itself if
- one really wants domains, instead of just comparable types as implemented
- in the C language. Any (decent) C compiler feels perfectly fine if one
- feeds it something like:
-
- #include <stdio.h>
- #include <string.h>
-
- typedef char* empnm_t;
- typedef char* beernm_t;
-
- int main() {
-
- empnm_t empnmBoss = "Clinton";
- beern_t beernMyFavBeer= "Grolsch";
-
- if (!strcmp(empnmBoss, beernMyFavBeer))
- printf("huh?\n");
-
- return 0;
-
- }
-
- The type definitions don't help, the prefixes don't add any clarity
- and still the program would run fine. If domains would have been implemented
- in C, both typedefs could have been changed into something like:
-
- domain char* empnm_d;
- domain char* beernm_d;
-
- and the compiler would have complained while parsing the arguments of
- the strcmp() function, i.e. two different domains were compared ...
-
- But if domains were implemented in C, we still don't need those explicit
- prefixes, because the compiler would have warned us about those domain
- violations, and, like you wrote above: if the semantics change, i.e. the
- domains change, one still has to change those prefixes accordingly if
- one used them ...
-
- kind regards,
-
- Jos aka jos@and.nl
- --
- Atnwgqkrl gy zit vgksr, ug qshiqwtzoeqs!
-
-